<template>
	<view class="collect">
		<view class="box" v-for="item in list">
			<view class="left">
				<image :src="item.largeImg" mode="widthFix"></image>
			</view>
			<view class="right">
				<view class="title">
					<text>{{item.name}}</text>
					<button class="btn" @click="RemoveCollectFn(item.pid)">取消收藏</button>
				</view>
				<view class="text">
					<text>{{item.desc}}</text>
				</view>
				<view class="price">
					<text>价格：{{item.price}}</text>
				</view>
				<view class="time">
					<text>{{item.createdAt}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { collectListFn,removeCollectFn } from '../../api/index.js';
	export default {
		data() {
			return {
				token:"",
				list:[]
			}
		},
		// onLoad(options) {
		// 	this.token = uni.getStorageSync('token');
		// 	this.CollectListFn();
		// },
		onShow() {
			this.token = uni.getStorageSync('token');
			this.CollectListFn();
		},
		methods: {
			async CollectListFn(){
				await collectListFn({
					appkey:"U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=",
					tokenString:this.token
				})
				.then(
					content=>{
						console.log(content);
						let {code,result,msg} = content;
						if(code == 2000){
							this.list = result;
						}
					}
				)
			},
			async RemoveCollectFn(pid){
				await removeCollectFn({
					appkey:"U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA=",
					pid:pid,
					tokenString:this.token
				})
				.then(
					content=>{
						console.log(content);
						let {code,msg} = content;
						if(code == 900){
							this.CollectListFn();
							uni.showToast({
								title:"取消收藏成功",
								duration:2000
							})
						}
					}
				)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.collect{
		margin: 40rpx 20rpx;
		.box{
			display: flex;
			width: 100%;
			// border: 1px solid black;
			margin-bottom: 40rpx;
			.left{
				width: 50%;
				image{
					width: 100%;
					border-radius: 20rpx;
				}
			}
			.right{
				width: 50%;
				padding-left: 10rpx;
				.title{
					display: flex;
					font-weight: bold;
					.btn{
						font-size: 24rpx;
						font-weight: 400;
						margin-top: 0;
						margin-bottom: 0;
						color: #ccc;
						background-color: #292b74;
						height: 40rpx;
						line-height: 40rpx;
						border-radius: 20rpx;
					}
				}
				.text{
					font-size: 24rpx;
					color: rgb(182, 174, 174);
					margin-top: 10rpx;
					margin-bottom: 20rpx;
					height: 100rpx;
					/*设置为弹性盒子*/
					display:-webkit-box;
					/* 表示几行后超出隐藏 */
					-webkit-line-clamp:3;
					overflow: hidden;
					text-overflow:ellipsis;
					-webkit-box-orient:vertical;
				}
				.price{
					font-size: 26rpx;
					margin-bottom: 10rpx;
				}
				.time{
					font-size: 24rpx;
					color: #ccc;
				}
			}
		}
	}
</style>
